#include "messageBox.h"

MessageBox::MessageBox()
{
	//按钮
	textEdit = new QTextEdit();
	questionBtn = new QPushButton("question");
	informationBtn = new QPushButton("information");
	warningBtn = new QPushButton("warning");
	criticalBtn = new QPushButton("critical");
	aboutBtn = new QPushButton("about");
	customBtn = new QPushButton("custom");
	
	//布局
	QVBoxLayout *vLay = new QVBoxLayout();
	vLay->addWidget(questionBtn);
	vLay->addWidget(informationBtn);
	vLay->addWidget(warningBtn);
	vLay->addWidget(criticalBtn);
	vLay->addWidget(aboutBtn);
	vLay->addWidget(customBtn);
	vLay->addWidget(textEdit);
	//整体布局
	setLayout(vLay);
	
	//关联信号和槽函数
	connect(questionBtn, SIGNAL(clicked()), this, SLOT(questionMsgSlot()));
	connect(informationBtn, SIGNAL(clicked()), this, SLOT(informationMsgSlot()));
	connect(warningBtn, SIGNAL(clicked()), this, SLOT(warningMsgSlot()));
	connect(criticalBtn, SIGNAL(clicked()), this, SLOT(criticalMsgSlot()));
	connect(aboutBtn, SIGNAL(clicked()), this, SLOT(aboutMsgSlot()));
	connect(customBtn, SIGNAL(clicked()), this, SLOT(customMsgSlot()));

}

void MessageBox::questionMsgSlot()
{
	textEdit->setText("you choose question MessageBox");
	//提问对话框，5个参数parent、title、text、按钮组、默认按钮
	switch(QMessageBox::question(this, "提问", "提问对话框实例",QMessageBox::Ok, QMessageBox::Open, QMessageBox::Save))
	{
		case QMessageBox::Ok:
			textEdit->append("you choose ok button");
			break;
		case QMessageBox::Open:
			textEdit->append("you choose open button");
			break;
		case QMessageBox::Save:
			textEdit->append("you choose save button");
			break;
		default:
			break;
	}
	return;
}
void MessageBox::informationMsgSlot()
{
	textEdit->setText("you choose information MessageBox");
	//信息对话框，5个参数parent、title、text、按钮组、默认按钮
	QMessageBox::information(this, tr("信息"), tr("信息对话框"));
	return;
}
void MessageBox::warningMsgSlot()
{
	//警告对话框，5个参数parent、title、text、按钮组、默认按钮
	textEdit->setText("you choose warning MessageBox");
	switch(QMessageBox::warning(this, tr("警告"), tr("警告对话框"),
		QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel, 
		QMessageBox::Save))
	{
		case QMessageBox::Save:
		textEdit->append("you choose save");
		break;
		case QMessageBox::Discard:
		textEdit->append("you choose Discard");
		break;
		case QMessageBox::Cancel:
		textEdit->append("you choose Cancel");
		break;
		default:
		break;
	}
	return ;
}
void MessageBox::criticalMsgSlot()
{
	textEdit->setText("you choose critical MessageBox");
	//critical对话框，5个参数parent、title、text、按钮组、默认按钮
	QMessageBox::critical(this, tr("critical"), tr("critical对话框"));
	return;
}
void MessageBox::customMsgSlot()
{
	//自定义对话框
	textEdit->setText("you choose custom MessageBox");
}
void MessageBox::aboutMsgSlot()
{
	textEdit->setText("you choose about MessageBox");
	//about对话框，三个参数parent、title、text
	QMessageBox::about(this, tr("about"), tr("about对话框"));
}

